package com.longrise.android.byjk.plugins.hra.hratabsecond;

import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.android.byjk.R;
import com.longrise.common.utils.AppUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/1/9.
 */

public class MineAppointDetailAdapter extends BaseQuickAdapter<EntityBean, BaseViewHolder> {

    private OnItemClickListener mListener;
    private List<EntityBean> mListBeans = new ArrayList<>();

    public MineAppointDetailAdapter() {
        super(R.layout.item_mine_appoint_detail);
    }

    public void refreshData(EntityBean[] beans) {
        mListBeans.clear();
        for (EntityBean bean : beans) {
            mListBeans.add(bean);
        }
        setNewData(mListBeans);
    }

    @Override
    protected void convert(BaseViewHolder helper, final EntityBean item) {
        final View convertView = helper.getConvertView();
        final TextView mMineAppointArea = (TextView) convertView.findViewById(R.id.item_mine_appoint_area);
        TextView mMineAppointName = (TextView) convertView.findViewById(R.id.item_test_name_tv);
        TextView mMineAppointTime = (TextView) convertView.findViewById(R.id.item_test_time_tv);
        final LinearLayout ll_mine_appoint_item = (LinearLayout) convertView.findViewById(R.id.ll_mine_appoint_item);

        mMineAppointArea.setText(item.getString("storename"));
        mMineAppointName.setText(item.getString("username"));
        mMineAppointTime.setText(item.getString("examinedate"));

        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.onItemClick(item);
                }
            }
        });

        mMineAppointArea.post(new Runnable() {
            @Override
            public void run() {
                int lineCount = mMineAppointArea.getLineCount();
                ViewGroup.LayoutParams layoutParams1 = ll_mine_appoint_item.getLayoutParams();
                ViewGroup.LayoutParams layoutParams = convertView.getLayoutParams();
                if (lineCount >= 2) {
                    layoutParams1.height = AppUtil.dip2px(70);
                    layoutParams.height = AppUtil.dip2px(197);
                } else {
                    layoutParams1.height = AppUtil.dip2px(47);
                    layoutParams.height = AppUtil.dip2px(174);
                }
                ll_mine_appoint_item.setLayoutParams(layoutParams1);
                convertView.setLayoutParams(layoutParams);
            }
        });
    }


    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mListener = listener;
    }

    public interface OnItemClickListener {

        void onItemClick(EntityBean item);
    }
}
